package com.ruoyi.web.controller.workflow;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.workflow.domain.WfForm;
import com.ruoyi.workflow.service.IWfFormService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 表单配置Controller
 * 
 * @author ruoyi
 * @date 2024-10-12
 */
@Api("表单配置")
@RestController
@RequestMapping("/workflow/form")
public class WfFormController extends BaseController
{
    @Autowired
    private IWfFormService wfFormService;

    /**
     * 查询表单配置列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:form:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfForm wfForm)
    {
        startPage();
        List<WfForm> list = wfFormService.selectWfFormList(wfForm);
        return getDataTable(list);
    }

    /**
     * 导出表单配置列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:form:export')")
    @Log(title = "表单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfForm wfForm)
    {
        List<WfForm> list = wfFormService.selectWfFormList(wfForm);
        ExcelUtil<WfForm> util = new ExcelUtil<WfForm>(WfForm.class);
        util.exportExcel(response, list, "表单配置数据");
    }

    /**
     * 获取表单配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:form:query')")
    @GetMapping(value = "/{formId}")
    public AjaxResult getInfo(@PathVariable("formId") Long formId)
    {
//        formId=1839128996120420353L;
        return success(wfFormService.selectWfFormByFormId(formId));
    }

    /**
     * 新增表单配置
     */
    @PreAuthorize("@ss.hasPermi('workflow:form:add')")
    @Log(title = "表单配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfForm wfForm)
    {
        return toAjax(wfFormService.insertWfForm(wfForm));
    }

    /**
     * 修改表单配置
     */
    @PreAuthorize("@ss.hasPermi('workflow:form:edit')")
    @Log(title = "表单配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfForm wfForm)
    {
        return toAjax(wfFormService.updateWfForm(wfForm));
    }

    /**
     * 删除表单配置
     */
    @PreAuthorize("@ss.hasPermi('workflow:form:remove')")
    @Log(title = "表单配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{formIds}")
    public AjaxResult remove(@PathVariable Long[] formIds)
    {
        return toAjax(wfFormService.deleteWfFormByFormIds(formIds));
    }
}
